﻿Public Class WebCredential
    Private Shared creds As Dictionary(Of String, WebCredential) = New Dictionary(Of String, WebCredential)()

    Private Shared TokenUrl As String = " https://api.yixin.im/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code"

    Public Property access_token() As String

    Public Property expires_in() As Integer

    Public Property add_time() As DateTime

    Public Property refresh_token() As String

    Public Property openid() As String

    Public Property scope() As String

    Public Property [error]() As ReturnCode

    Friend Shared Function GetCredential(appId As String, appSecret As String, code As String) As WebCredential
        Dim json As String = Util.HttpGet2(String.Format(WebCredential.TokenUrl, appId, appSecret, code))
        Dim cred As WebCredential
        If json.IndexOf("errcode") >= 0 Then
            cred = New WebCredential()
            cred.[error] = Util.JsonTo(Of ReturnCode)(json)
        Else
            cred = Util.JsonTo(Of WebCredential)(json)
        End If
        Return cred
    End Function
End Class

